package cn.sm1234.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyHandlerExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {

        ModelAndView mv = new ModelAndView();

        if (e instanceof ArithmeticException){
            mv.setViewName("erro1");
        }
        if (e instanceof NullPointerException){
            mv.setViewName("error2");
        }

        mv.addObject("exception", e.toString());

        return mv;
    }
}
